﻿//记住 添加引用 System.ServiceModel.Web      
/**      
 * 如果不添加上面的引用,System.Runtime.Serialization.Json; Json
 * 是出不来的哦      * 
 */


using System.Web.Script.Serialization;

namespace MvcApplication2
{
    public static class ObjExtenins
    {
        public static string ToJson(this object t)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Serialize(t);
        }

        public static T ToT<T>(string jsonString)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Deserialize<T>(jsonString);
        }
    }
}
